﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;
using System.IO;

public partial class Week_WeekPlanDisplay : System.Web.UI.Page
{
    UserInfoManager dllUserInfoManager = new UserInfoManager();
    IBussinessLogic dllMonthPlan = new MonthPlanManager();
    WeekDateManager dllWeekDateManager = new WeekDateManager();
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    MonthDateManager dllMonthDateManager = new MonthDateManager();
    IBussinessLogic dllUserInfo = new UserInfoManager();
    WeekPlanofManager dllWeekPlanofManager = new WeekPlanofManager();
    Authentication dllAuthentication = new Authentication();
    Week_RemindofManager dllWeek_RemindofManager = new Week_RemindofManager();
    DepartmentInfoManager dllDepartment = new DepartmentInfoManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new DataTable();
    public string PreWeekRemind = "";
    public string TheWeekRemind = ""; int _isManager = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();

        //判断是否为经理，非经理锁定部门选择框
        this.drpDepartment.Enabled = false;
        IsManager();


        //得到周计划信息  
        if (!IsPostBack)
        {
            ////获得下拉列表的信息
            bindDropDownList(this.drpDepartment);
            if (Request.Params["depart"] != null && Request.Params["depart"].ToString().Length != 0 && Request.Params["depart"].ToString() != "请选择部门")
            {
                string did = Request.Params["depart"].ToString();
                this.drpDepartment.SelectedValue = did;
            }
            if (Request.Params["department"] != null && Request.Params["department"].ToString().Length != 0 && Request.Params["department"].ToString() != "请选择部门")
            {
                string department = Server.UrlDecode(Request.Params["department"].ToString());
                this.drpDepartment.SelectedIndex = this.drpDepartment.Items.IndexOf(this.drpDepartment.Items.FindByText(department));
            }
            bindDropDownList(this.drpYear);
            if (Request.Params["Year"] != null && Request.Params["Year"].ToString().Length != 0)
            {
                string Year = Server.UrlDecode(Request.Params["Year"].ToString());
                this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(Year));
            }
            bindDropDownList(this.drpQuarterDate);
            if (Request.Params["Quarter"] != null && Request.Params["Quarter"].ToString().Length != 0)
            {
                string Quarter = Server.UrlDecode(Request.Params["Quarter"].ToString());
                this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByValue(Quarter));
            }
            bindDropDownList(this.drpMonthDate);
            if (Request.Params["Month"] != null && Request.Params["Month"].ToString().Length != 0)
            {
                string Month = Server.UrlDecode(Request.Params["Month"].ToString());
                this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByValue(Month));
            }
            bindDropDownList(this.drpWeekDate);
            if (Request.Params["Week"] != null && Request.Params["Week"].ToString().Length != 0)
            {
                string Week = Server.UrlDecode(Request.Params["Week"].ToString());
                this.drpWeekDate.SelectedIndex = this.drpWeekDate.Items.IndexOf(this.drpWeekDate.Items.FindByValue(Week));
            }





            bindGridView(this.gdvWeekPlan);
            bindGridView(this.gdvPreWeekPlan);
            bindGridView(this.gdvPreWeekPlanNoCompelete);
            bindGridView(this.gdvWeekPlanContinue);
            bindWeekRemind();
        }
        processGridViewForWeek(gdvWeekPlan);
        processGridViewPre(gdvPreWeekPlan);
        processGridViewForWeek(gdvPreWeekPlanNoCompelete);
        processGridView(gdvWeekPlanContinue);
    }


    void IsManager()
    {
        _isManager = dllAuthentication.IsManager(objUserInfo.UserName);
        if (_isManager > 0)
        {
            this.drpDepartment.Enabled = true; 
            this.btnToExcel.Visible = true; 
            this.btnAddPreWeekSummary.Enabled = true;
            this.btnAddWeekSummary.Enabled = true;
            this.btnDownPreWeek.Enabled = true;
            this.btnDownWeekSummary.Enabled = true;
            this.btnUploadPreWeekSummary.Enabled = true;
            this.btnUploadWeekSummary.Enabled = true;
            this.btnSavePreWeekSummary.Enabled = true;
            this.btnSaveWeekSummary.Enabled = true;
        }
        else
        {
            this.drpDepartment.Enabled = false;  
            this.btnToExcel.Visible = false;  
            this.btnAddPreWeekSummary.Enabled = false;
            this.btnAddWeekSummary.Enabled = false;
            this.btnDownPreWeek.Enabled = false;
            this.btnDownWeekSummary.Enabled = false;
            this.btnUploadPreWeekSummary.Enabled = false;
            this.btnUploadWeekSummary.Enabled = false;
            this.btnSavePreWeekSummary.Enabled = false;
            this.btnSaveWeekSummary.Enabled = false;
        }
    }

    /// <summary>
    /// 绑定所有的dropdownlist
    /// </summary>
    /// <param name="_drp"></param>
    void bindDropDownList(DropDownList _drp)
    {//部门绑定
        if (_drp.Equals(this.drpDepartment))
        {
            this.drpDepartment.DataSource = dllDepartment.getNoTree();
            this.drpDepartment.DataTextField = "DepartmentName";
            this.drpDepartment.DataValueField = "DepartmentId";
            this.drpDepartment.DataBind();
            ListItem _li = new ListItem("请选择部门");
            this.drpDepartment.Items.Insert(0, _li);
        }
        //年份绑定
        if (_drp.Equals(this.drpYear))
        {
            for (int i = 2009; i < 2100; i++)
            {
                ListItem _li = new ListItem(i.ToString(), i.ToString());
                _drp.Items.Add(_li);
            }
            //根据系统日期自动绑定到当前年份
            string _year = DateTime.Now.Year.ToString();
            this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year));

        }

        //绑定年计划周期
        if (_drp.Equals(this.drpQuarterDate))
        {
            object[] _value = new object[1];
            _value[0] = this.drpYear.SelectedValue;
            DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
            if (_quarter.Rows.Count != 0)
            {
                this.drpQuarterDate.DataSource = _quarter;
                this.drpQuarterDate.DataTextField = "QuarterName";
                this.drpQuarterDate.DataValueField = "Quarter_Id";
                this.drpQuarterDate.DataBind();
                #region dropdownlist显示系统所对应的当前年周期
                //根据系统当前日期查找到对应的年周期
                DataTable _quartertime = dllQuarterDateManager.getQuarterDate();
                //如果查到结果（结果只有一条）

                if (_quartertime.Rows.Count == 1)
                {
                    this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByText(_quartertime.Rows[0][1].ToString()));

                }
                #endregion
                bindDropDownList(this.drpMonthDate);
            }
            else
            {
                ListItem _li = new ListItem("无年周期", "0");
                this.drpQuarterDate.Items.Clear();
                this.drpQuarterDate.Items.Add(_li);
                bindDropDownList(this.drpMonthDate);
            }

        }

        //绑定月计划周期
        if (_drp.Equals(this.drpMonthDate))
        {
            object[] _value = new object[2];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            DataTable _month = dllMonthDateManager.get(MonthDateManager.field.QuarterName.ToString(), _value);
            if (_month.Rows.Count != 0)
            {
                this.drpMonthDate.DataSource = _month;
                this.drpMonthDate.DataTextField = "MonthName";
                this.drpMonthDate.DataValueField = "Month_Id";
                this.drpMonthDate.DataBind();
                #region 根据系统当前日期绑定到当前月周期
                DataTable _monthtime = dllMonthDateManager.getMonthDate();
                if (_monthtime.Rows.Count == 1)
                {
                    this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByText(_monthtime.Rows[0][3].ToString()));


                }
                #endregion
                bindDropDownList(this.drpWeekDate);
            }
            else
            {
                ListItem _li = new ListItem("无月周期", "0");
                this.drpMonthDate.Items.Clear();
                this.drpMonthDate.Items.Add(_li);
                bindDropDownList(this.drpWeekDate);
            }

        }
        //绑定周计划周期
        if (_drp.Equals(this.drpWeekDate))
        {
            object[] _value = new object[3];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            _value[2] = this.drpMonthDate.SelectedItem.Text;
            DataTable _week = dllWeekDateManager.get(WeekDateManager.field.MonthName.ToString(), _value);
            if (_week.Rows.Count != 0)
            {
                this.drpWeekDate.DataSource = _week;
                this.drpWeekDate.DataTextField = "WeekName";
                this.drpWeekDate.DataValueField = "Week_Id";
                this.drpWeekDate.DataBind();
                DataTable _weektime = dllWeekDateManager.getWeekDate();
                if (_weektime.Rows.Count == 1)
                {
                    this.drpWeekDate.SelectedIndex = this.drpWeekDate.Items.IndexOf(this.drpWeekDate.Items.FindByText(_weektime.Rows[0][3].ToString()));
                    if (Request.QueryString["Id"] != null)
                    {
                        this.drpWeekDate.SelectedIndex = this.drpWeekDate.Items.IndexOf(this.drpWeekDate.Items.FindByValue(Request.QueryString["Id"].ToString()));
                    }
                }
                bindGridView(this.gdvWeekPlan);
                bindGridView(this.gdvPreWeekPlan);
                bindGridView(this.gdvPreWeekPlanNoCompelete);
                bindGridView(this.gdvWeekPlanContinue);
                bindWeekRemind();
            }
            else
            {
                ListItem _li = new ListItem("无周周期", "0");
                this.drpWeekDate.Items.Clear();
                this.drpWeekDate.Items.Add(_li);
                bindGridView(this.gdvWeekPlan);
                bindGridView(this.gdvPreWeekPlan);
                bindGridView(this.gdvPreWeekPlanNoCompelete);
                bindGridView(this.gdvWeekPlanContinue);
                bindWeekRemind();
            }
        }

    }



    /// <summary>
    /// 绑定GridView
    /// </summary>
    /// <author>gzz</author>
    /// <date>2009-1-4</date>
    void bindWeekRemind()
    {
        this.lblWeekRemind.Text = "";
        this.lblPreWeekRemind.Text = "";
        //获得Session中登陆用户的用户名
        object[] _user = new object[1];
        Model.UserInfo objUserInfo = new Model.UserInfo();
        _user[0] = objUserInfo.UserName;
        //根据用户名获得用户真实姓名
        DataTable _userInfo = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
        object[] _value = new object[2];
        _value[0] = this.drpDepartment.SelectedItem.Text;
        _value[1] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
        //根据用户所在部门和当前时间查询月工作提醒
        DataTable _preWeekRemind = dllWeek_RemindofManager.getPreWeekRemind(_value);
        DataTable _theWeekRemind = dllWeek_RemindofManager.getTheWeekRemind(_value);
        if (_preWeekRemind.Rows.Count > 0)
        {
            for (int i = 0; i < _preWeekRemind.Rows.Count; i++)
            {
                int _sortId = 0;
                _sortId = i + 1;
                this.lblPreWeekRemind.Text += _sortId + ":" + _preWeekRemind.Rows[i]["TheWeekRemind"].ToString() + "\r\n";
            }
        }
        if (_theWeekRemind.Rows.Count > 0)
        {
            for (int i = 0; i < _theWeekRemind.Rows.Count; i++)
            {
                int _sortId = 0;
                _sortId = i + 1;
                this.lblWeekRemind.Text += _sortId + ":" + _theWeekRemind.Rows[i]["TheWeekRemind"].ToString() + "\r\n";
            }
        }
    }


    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");


    }
    //构建上周计划表结构并添加1行
    DataTable createDataTable()
    {
        DataTable _dt = new DataTable();
        DataColumn dc = new DataColumn("WeekPlanSortId");
        _dt.Columns.Add(dc);
        dc = new DataColumn("WorkItem");
        _dt.Columns.Add(dc);
        dc = new DataColumn("Source");
        _dt.Columns.Add(dc);
        dc = new DataColumn("CompleteTime");
        _dt.Columns.Add(dc);
        dc = new DataColumn("MasterPeople");
        _dt.Columns.Add(dc);
        dc = new DataColumn("SlaveDepartment");
        _dt.Columns.Add(dc);
        dc = new DataColumn("SlaveDepartmentDuty");
        _dt.Columns.Add(dc);
        dc = new DataColumn("EvaluatePeople");
        _dt.Columns.Add(dc);
        dc = new DataColumn("PlanSendState");
        _dt.Columns.Add(dc);
        dc = new DataColumn("CheckNote");
        _dt.Columns.Add(dc);
        dc = new DataColumn("Remart");
        _dt.Columns.Add(dc);
        dc = new DataColumn("WeekPlanId");
        _dt.Columns.Add(dc);
        dc = new DataColumn("MonthPlanId");
        _dt.Columns.Add(dc);
        dc = new DataColumn("NoCompleteCount");
        _dt.Columns.Add(dc);
        dc = new DataColumn("VerifyPeopleOpinion");
        _dt.Columns.Add(dc);
        dc = new DataColumn("PlanStep");
        _dt.Columns.Add(dc);
        DataRow dr = _dt.NewRow();
        dr["WeekPlanSortId"] = "";
        dr["WorkItem"] = "";
        dr["Source"] = "";
        dr["CompleteTime"] = "";
        dr["MasterPeople"] = "";
        dr["SlaveDepartment"] = "";
        dr["SlaveDepartmentDuty"] = "";
        dr["EvaluatePeople"] = "";
        dr["PlanSendState"] = "0";
        dr["CheckNote"] = "";
        dr["Remart"] = "";
        dr["MonthPlanId"] = "";
        dr["WeekPlanId"] = "";
        dr["NoCompleteCount"] = "";
        dr["VerifyPeopleOpinion"] = "";
        dr["PlanStep"] = "";
        _dt.Rows.Add(dr);
        return _dt;
    }

    /// <summary>
    /// 绑定gridview
    /// </summary>
    void bindGridView(GridView _gridView)
    {
        if (_gridView.Equals(this.gdvPreWeekPlan))
        {
            #region 绑定上周计划
            this.gdvPreWeekPlan.DataSource = new DataTable();
            this.gdvPreWeekPlan.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            _value[1] = _objUserInfo.UserName;
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _weekPlan = dllWeekPlanofManager.getPreWeekPlan(_value);
            if (_weekPlan.Tables.Count > 1)
            {
                for (int j = 1; j < _weekPlan.Tables.Count; j++)
                {
                    if (_weekPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_weekPlan.Tables[j]);
                        dv.Sort = "WeekPlanSortId";
                        this.gdvPreWeekPlan.DataSource = dv;
                        this.gdvPreWeekPlan.DataBind();
                    }
                }
            }
            if (this.gdvPreWeekPlan.Rows.Count == 0)
            {
                this.gdvPreWeekPlan.DataSource = createDataTable();
                this.gdvPreWeekPlan.DataBind();
            }

            #endregion
        }
        if (_gridView.Equals(this.gdvPreWeekPlan))
        {
            object[] _valueSummary = new object[2];
            _valueSummary[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            _valueSummary[1] = this.drpDepartment.SelectedItem.Text;
            DataTable dt = new BLL.WeekSummary().get(BLL.WeekSummary.field.WeekDate.ToString(), BLL.WeekSummary.field.Department.ToString(), _valueSummary);
            if (dt.Rows.Count > 0)
            {
                this.txtWeekSummary.Text = dt.Rows[0]["WeekSummary"].ToString();
                this.txtPreWeekSummary.Text = dt.Rows[0]["PreWeekSummary"].ToString();
                this.prelength.InnerHtml = this.txtPreWeekSummary.Text.Length.ToString();
                this.thelength.InnerHtml = this.txtWeekSummary.Text.Length.ToString();
                this.HWeekSummaryId.Value = dt.Rows[0]["Id"].ToString();
                this.HPreAttachmentPath.Value = dt.Rows[0]["PreAttachmentPath"].ToString();
                this.HAttachmentPath.Value = dt.Rows[0]["AttachmentPath"].ToString();
            }
            else
            {
                this.txtWeekSummary.Text = "注：工作部署不少于3条，总字数不少于60个字。";
                this.txtPreWeekSummary.Text = "注：工作总结不少于3条，总字数不少于60个字。";
                this.prelength.InnerHtml = "0";
                this.thelength.InnerHtml = "0";
                this.HWeekSummaryId.Value = string.Empty;
                this.HPreAttachmentPath.Value = string.Empty;
                this.HAttachmentPath.Value = string.Empty;
            }
            if (this.txtWeekSummary.Text.Length > 0 && this.txtWeekSummary.Text != "注：工作部署不少于3条，总字数不少于60个字。")
            {
                this.btnAddWeekSummary.Text = "修改";
            }
            else
            {
                this.btnAddWeekSummary.Text = "添加";
            }
            if (this.txtPreWeekSummary.Text.Length > 0 && this.txtPreWeekSummary.Text != "注：工作总结不少于3条，总字数不少于60个字。")
            {
                this.btnAddPreWeekSummary.Text = "修改";
            }
            else
            {
                this.btnAddPreWeekSummary.Text = "添加";
            }
            if (this.HPreAttachmentPath.Value.Length > 0)
            {
                this.btnDownPreWeek.Enabled = true;
            }
            else
            {
                this.btnDownPreWeek.Enabled = false;
            }
            if (this.HAttachmentPath.Value.Length > 0)
            {
                this.btnDownWeekSummary.Enabled = true;
            }
            else
            {
                this.btnDownWeekSummary.Enabled = false;
            }
            if (objUserInfo.UserName != "admin")
            {
                bool Isdepartment = false;
                //当前部门并且当前月份
                object[] _value = new object[1];
                _value[0] = objUserInfo.UserName;
                DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _value);
                if (_userTable.Rows.Count > 0)
                {
                    if (_userTable.Rows[0]["DepartmentId"].ToString() == this.drpDepartment.SelectedItem.Text || _userTable.Rows[0]["PartTimeDepartmentId"].ToString() == this.drpDepartment.SelectedItem.Text)
                    {
                        Isdepartment = true;
                    }
                }

                bool IsDate = new BLL.WeekDateManager().IsEditWeekSummary(new object[] { Convert.ToInt32(this.drpWeekDate.SelectedValue) });
                //DataTable _weektime = dllWeekDateManager.getWeekDate();
                //if (this.drpWeekDate.SelectedItem.Text == _weektime.Rows[0][4].ToString())
                //{
                //    IsDate = true;

                //}
                if (Isdepartment && IsDate)
                {

                    this.btnAddPreWeekSummary.Enabled = true;
                    this.btnAddWeekSummary.Enabled = true;
                    this.btnUploadPreWeekSummary.Enabled = true;
                    this.btnUploadWeekSummary.Enabled = true;
                }
                else
                {
                    this.btnAddPreWeekSummary.Enabled = false;
                    this.btnAddWeekSummary.Enabled = false;
                    this.btnUploadWeekSummary.Enabled = false;
                    this.btnUploadPreWeekSummary.Enabled = false;
                }
                this.btnSaveWeekSummary.Visible = false;
                this.btnSavePreWeekSummary.Visible = false;
                this.btnAddWeekSummary.Visible = true;
                this.btnAddPreWeekSummary.Visible = true;
            }
            this.txtPreWeekSummary.ReadOnly = true;
            this.txtWeekSummary.ReadOnly = true;
        }
        if (_gridView.Equals(this.gdvWeekPlan))
        {
            #region 绑定本周计划
            //得到用户名
            this.gdvWeekPlan.DataSource = new DataTable();
            this.gdvWeekPlan.DataBind();
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            _value[1] = _objUserInfo.UserName;
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _weekPlan = dllWeekPlanofManager.getWeekPlan(_value);
            if (_weekPlan.Tables.Count > 1)
            {
                for (int j = 1; j < _weekPlan.Tables.Count; j++)
                {
                    if (_weekPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_weekPlan.Tables[j]);
                        dv.Sort = "WeekPlanSortId";
                        this.gdvWeekPlan.DataSource = dv;
                        this.gdvWeekPlan.DataBind();
                    }
                }
            }

            if (this.gdvWeekPlan.Rows.Count == 0)
            {
                this.gdvWeekPlan.DataSource = createDataTable();
                this.gdvWeekPlan.DataBind();
            }

            #endregion
        }
        if (_gridView.Equals(this.gdvPreWeekPlanNoCompelete))
        {
            #region 绑定上周未完成计划
            this.gdvPreWeekPlanNoCompelete.DataSource = new DataTable();
            this.gdvPreWeekPlanNoCompelete.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            _value[1] = _objUserInfo.UserName;
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _weekPlan = dllWeekPlanofManager.getPreWeekPlanNoComplete(_value);
            if (_weekPlan.Tables.Count > 1)
            {
                for (int j = 1; j < _weekPlan.Tables.Count; j++)
                {
                    if (_weekPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_weekPlan.Tables[j]);
                        dv.Sort = "WeekPlanSortId";
                        this.gdvPreWeekPlanNoCompelete.DataSource = dv;
                        this.gdvPreWeekPlanNoCompelete.DataBind();
                    }
                }
            }

            if (this.gdvPreWeekPlanNoCompelete.Rows.Count == 0)
            {
                this.gdvPreWeekPlanNoCompelete.DataSource = createDataTable();
                this.gdvPreWeekPlanNoCompelete.DataBind();
            }

            #endregion
        }
        if (_gridView.Equals(this.gdvWeekPlanContinue))
        {
            #region 绑定上周持续计划
            this.gdvWeekPlanContinue.DataSource = new DataTable();
            this.gdvWeekPlanContinue.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            _value[1] = _objUserInfo.UserName;
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _weekPlan = dllWeekPlanofManager.getWeekPlanContinue(_value);
            if (_weekPlan.Tables.Count > 1)
            {
                for (int j = 1; j < _weekPlan.Tables.Count; j++)
                {
                    if (_weekPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_weekPlan.Tables[j]);
                        dv.Sort = "WeekPlanSortId";
                        this.gdvWeekPlanContinue.DataSource = dv;
                        this.gdvWeekPlanContinue.DataBind();
                    }
                }
            }
            if (this.gdvWeekPlanContinue.Rows.Count == 0)
            {
                this.gdvWeekPlanContinue.DataSource = createDataTable();
                this.gdvWeekPlanContinue.DataBind();
            }

            #endregion
        }


        #region 处理日期和来源
        if (_gridView.Equals(this.gdvWeekPlan) || _gridView.Equals(this.gdvWeekPlanContinue))
        {
            processGridViewForWeek(_gridView);
        }

        if (_gridView.Equals(this.gdvPreWeekPlanNoCompelete))
        {
            processGridView(_gridView);
        }
        if (_gridView.Equals(this.gdvPreWeekPlan))
        {
            processGridViewPre(_gridView);
        }
        #endregion


    }

    /// <summary>
    /// 处理日期和来源显示
    /// </summary>
    /// <param name="_gridView"></param>
    void processGridView(GridView _gridView)
    {
        for (int i = 0; i < _gridView.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)_gridView.Rows[i].Cells[1].FindControl("lbtnSource");
            lbtn.Text = _gridView.DataKeys[i]["Source"].ToString();
            wrapByComma(_gridView, i, 6);
            wrapByComma(_gridView, i, 7);
            _gridView.Rows[i].Cells[8].Text = _gridView.Rows[i].Cells[8].Text.Replace("&", "");
            _gridView.Rows[i].Cells[8].Text = _gridView.Rows[i].Cells[8].Text.Replace("nbsp;", "");
            _gridView.Rows[i].Cells[8].Text = _gridView.Rows[i].Cells[8].Text.Replace("amp;", "");
            if (_gridView.DataKeys[i]["PlanSendState"].ToString() != "&nbsp;" && _gridView.DataKeys[i]["PlanSendState"].ToString() != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            {

                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 8)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Gray;
                }

                //判断2次以上变红为失控状态
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //失控标红
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 9)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
                //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                //{
                //    _gridView.Rows[i].Cells[9].Text = "达成共识<br>" + _gridView.Rows[i].Cells[9].Text;
                //}
                //else
                //{
                //    _gridView.Rows[i].Cells[9].Text = "";
                //}
            }
            else
            {
                //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                //{
                //    _gridView.Rows[i].Cells[9].Text = "达成共识";
                //}
                //else
                //{
                //    _gridView.Rows[i].Cells[9].Text = "";
                //}
            }
            if (_gridView.Rows[i].Cells[8].Text == "&nbsp;" || _gridView.Rows[i].Cells[8].Text == "&amp;nbsp;")
            {
                _gridView.Rows[i].Cells[8].Text = "";
            }

            #region 2010-06-03评估人意见和达成共识合并
            //if (_gridView.DataKeys[i]["PlanSendState"].ToString() != "&nbsp;" && _gridView.DataKeys[i]["PlanSendState"].ToString() != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            //{

            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
            //    }

            //    //判断2次以上变红为失控状态
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    //失控标红
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].Cells[10].Text = "达成共识";
            //    }
            //    else
            //    {
            //        _gridView.Rows[i].Cells[10].Text = "";
            //    }
            //}
            //else
            //{
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].Cells[10].Text = "达成共识";
            //    }
            //    else
            //    {
            //        _gridView.Rows[i].Cells[10].Text = "";
            //    }
            //}
            //if (_gridView.Rows[i].Cells[11].Text == "&nbsp;" || _gridView.Rows[i].Cells[11].Text == "&amp;nbsp;")
            //{
            //    _gridView.Rows[i].Cells[11].Text = "";
            //}
            #endregion
        }
    }

    /// <summary>
    /// 处理日期和来源显示
    /// </summary>
    /// <param name="_gridView"></param>
    void processGridViewPre(GridView _gridView)
    {
        for (int i = 0; i < _gridView.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)_gridView.Rows[i].Cells[1].FindControl("lbtnSource");
            lbtn.Text = _gridView.DataKeys[i]["Source"].ToString();
            wrapByComma(_gridView, i, 6);
            wrapByComma(_gridView, i, 7);

            if (_gridView.DataKeys[i]["PlanSendState"].ToString() != "&nbsp;" && _gridView.DataKeys[i]["PlanSendState"].ToString() != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            {

                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
                }

                //判断2次以上变红为失控状态
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //失控标红
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //调整变灰色
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 8)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Gray;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 9)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
                //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                //{
                //    _gridView.Rows[i].Cells[10].Text = "达成共识<br>" + _gridView.Rows[i].Cells[10].Text;
                //}
                //else
                //{
                //    _gridView.Rows[i].Cells[10].Text = "";
                //}
            }
            else
            {
                //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                //{
                //    _gridView.Rows[i].Cells[10].Text = "达成共识";
                //}
                //else
                //{
                //    _gridView.Rows[i].Cells[10].Text = "";
                //}
            }
            if (_gridView.Rows[i].Cells[8].Text == "&nbsp;" || _gridView.Rows[i].Cells[8].Text == "&amp;nbsp;")
            {
                _gridView.Rows[i].Cells[8].Text = "";
            }

            #region 2010-06-03评估人意见和达成共识合并
            //if (_gridView.DataKeys[i]["PlanSendState"].ToString() != "&nbsp;" && _gridView.DataKeys[i]["PlanSendState"].ToString() != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            //{

            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
            //    }

            //    //判断2次以上变红为失控状态
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    //失控标红
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].Cells[9].Text = "达成共识";
            //    }
            //    else
            //    {
            //        _gridView.Rows[i].Cells[9].Text = "";
            //    }
            //}
            //else
            //{
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].Cells[9].Text = "达成共识";
            //    }
            //    else
            //    {
            //        _gridView.Rows[i].Cells[9].Text = "";
            //    }
            //}
            //if (_gridView.Rows[i].Cells[10].Text == "&nbsp;" || _gridView.Rows[i].Cells[10].Text == "&amp;nbsp;")
            //{
            //    _gridView.Rows[i].Cells[10].Text = "";
            //}
            #endregion
        }
    }


    /// <summary>
    /// 处理日期和来源显示
    /// </summary>
    /// <param name="_gridView"></param>
    void processGridViewForWeek(GridView _gridView)
    {
        for (int i = 0; i < _gridView.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)_gridView.Rows[i].Cells[1].FindControl("lbtnSource");
            lbtn.Text = _gridView.DataKeys[i]["Source"].ToString();
            wrapByComma(_gridView, i, 6);

            if (_gridView.DataKeys[i]["PlanSendState"].ToString() != "&nbsp;" && _gridView.DataKeys[i]["PlanSendState"] != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            {
                //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                //{
                //    _gridView.Rows[i].Cells[9].Text = "达成共识<br>" + _gridView.Rows[i].Cells[9].Text;
                //}
                //else
                //{
                //    _gridView.Rows[i].Cells[9].Text = "";
                //}
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 9)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 8)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Gray;
                }
            }
            if (_gridView.Rows[i].Cells[8].Text == "&nbsp;" || _gridView.Rows[i].Cells[8].Text == "&amp;nbsp;")
            {
                _gridView.Rows[i].Cells[8].Text = "";
            }
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[9].Text = "";
            //}

            #region 2010-06-03评估人意见和达成共识合并
            //if (_gridView.Rows[i].Cells[10].Text != "&nbsp;" && _gridView.Rows[i].Cells[10].Text != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            //{
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].Cells[10].Text = "达成共识";
            //    }
            //    else
            //    {
            //        _gridView.Rows[i].Cells[10].Text = "";
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
            //    }
            //}
            //if (_gridView.Rows[i].Cells[11].Text == "&nbsp;" || _gridView.Rows[i].Cells[11].Text == "&amp;nbsp;")
            //{
            //    _gridView.Rows[i].Cells[11].Text = "";
            //}
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[10].Text = "";
            //}
            #endregion
        }
    }





    protected void gvlist_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gdvWeekPlan.PageIndex = e.NewPageIndex;
        bindGridView(this.gdvWeekPlan);
    }


    /// <summary>
    /// 上周计划来源链接事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSourcePreWeekPlan_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行         
        i = iRow.RowIndex;//得到该行的索引
        int _monthPlanId = Convert.ToInt32(this.gdvPreWeekPlan.DataKeys[i]["MonthPlanId"].ToString());
        if (_monthPlanId == 0)
        {
            //新增的不链接页面
        }
        else
        {
            string _url = "MonthPlanDetail.aspx?MonthPlanId=" + _monthPlanId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','preweek','height=200,width=902,top=300,left=80,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no');</script>");
        }
    }


    /// <summary>
    /// 本周计划来源链接事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSourceWeekPlan_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行         
        i = iRow.RowIndex;//得到该行的索引
        int _monthPlanId = Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["MonthPlanId"].ToString());
        if (_monthPlanId == 0)
        {
            //新增的不链接页面
        }
        else
        {
            string _url = "MonthPlanDetail.aspx?MonthPlanId=" + _monthPlanId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','theweek','height=200,width=902,top=300,left=80,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no');</script>");
        }
    }



    /// <summary>
    /// 上周未完成计划来源链接事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSourcePreWeekPlanNoCompe_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行         
        i = iRow.RowIndex;//得到该行的索引
        int _monthPlanId = Convert.ToInt32(this.gdvPreWeekPlanNoCompelete.DataKeys[i]["MonthPlanId"].ToString());
        if (_monthPlanId == 0)
        {
            //新增的不链接页面
        }
        else
        {
            string _url = "MonthPlanDetail.aspx?MonthPlanId=" + _monthPlanId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','preweeknocom','height=200,width=902,top=300,left=80,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no');</script>");
        }
    }



    /// <summary>
    /// 持续计划来源链接事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSourceWeekPlanContinue_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行         
        i = iRow.RowIndex;//得到该行的索引
        int _monthPlanId = Convert.ToInt32(this.gdvWeekPlanContinue.DataKeys[i]["MonthPlanId"].ToString());
        if (_monthPlanId == 0)
        {
            //新增的不链接页面
        }
        else
        {
            string _url = "MonthPlanDetail.aspx?MonthPlanId=" + _monthPlanId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','weekcontinue','height=200,width=902,top=300,left=80,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no');</script>");
        }
    }




    /// <summary>
    /// dropDownList项改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-3-11</date>
    protected void drpDepartment_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.drpDepartment.SelectedItem != null && this.drpDepartment.SelectedItem.Text != "请选择部门")
        {
            bindGridView(this.gdvWeekPlan);
            bindGridView(this.gdvPreWeekPlan);
            bindGridView(this.gdvPreWeekPlanNoCompelete);
            bindGridView(this.gdvWeekPlanContinue);
            bindWeekRemind();
        }
        this.btnAddWeekSummary.Visible = true;
        this.btnAddPreWeekSummary.Visible = true;
        this.btnSaveWeekSummary.Visible = false;
        this.btnSavePreWeekSummary.Visible = false;
    }





    //本周计划修改
    protected void btnWeekPlan_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;
        int _count = 0;
        int _weekId = 0;
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvWeekPlan.DataKeys[i]["WeekPlanId"] != null && this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {

                    _weekId = Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        if (_count == 1)
        {
            //判断是否为评估人，如果该条计划的评估人是当前用户则不能修改该条计划
            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[3];
                _username[0] = objUserInfo.UserName;
                _username[1] = _userTable.Rows[0]["RealName"].ToString();
                _username[2] = _weekId;
                DataTable _iSEvaluatePeople = dllWeekPlanofManager.get(WeekPlanofManager.field.EvaluatePeople.ToString(), WeekPlanofManager.field.WeekPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count == 0 && objUserInfo.UserName != "admin")
                {
                    Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                }
                else
                {
                    string _url = "WeekPlanModify.aspx?Id=" + _weekId + "&WeekDate=" + this.drpWeekDate.SelectedValue + "&depart=" + department + "&Year=" + this.drpYear.SelectedValue + "&Quarter=" + this.drpQuarterDate.SelectedValue + "&Month=" + this.drpMonthDate.SelectedValue + "&Week=" + this.drpWeekDate.SelectedValue;
                    Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
                    return;
                }
            }


        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能查看一个周计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个周计划", Page);
            return;
        }
    }


    /// <summary>
    /// 上周未完成计划修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPreWeekPlanNoCom_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;
        int _count = 0;
        int _weekId = 0;
        for (int i = 0; i < this.gdvPreWeekPlanNoCompelete.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreWeekPlanNoCompelete.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"] != null && this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {
                    _weekId = Convert.ToInt32(this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        if (_count == 1)
        {
            //判断是否为评估人，如果该条计划的评估人是当前用户则不能修改该条计划
            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[3];
                _username[0] = objUserInfo.UserName;
                _username[1] = _userTable.Rows[0]["RealName"].ToString();
                _username[2] = _weekId;
                DataTable _iSEvaluatePeople = dllWeekPlanofManager.get(WeekPlanofManager.field.EvaluatePeople.ToString(), WeekPlanofManager.field.WeekPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count == 0 && objUserInfo.UserName != "admin")
                {
                    Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                }
                else
                {
                    string _url = "WeekPlanModify.aspx?Id=" + _weekId + "&WeekDate=" + this.drpWeekDate.SelectedValue + "&depart=" + department + "&Year=" + this.drpYear.SelectedValue + "&Quarter=" + this.drpQuarterDate.SelectedValue + "&Month=" + this.drpMonthDate.SelectedValue + "&Week=" + this.drpWeekDate.SelectedValue;
                    Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
                    return;
                }
            }

        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能查看一个周计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个周计划", Page);
            return;
        }
    }


    //持续计划修改
    protected void btnWeekPlanContinue_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;
        int _count = 0;
        int _weekId = 0;
        for (int i = 0; i < this.gdvWeekPlanContinue.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlanContinue.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"] != null && this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {
                    _weekId = Convert.ToInt32(this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        if (_count == 1)
        { //判断是否为评估人，如果该条计划的评估人是当前用户则不能修改该条计划
            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[3];
                _username[0] = objUserInfo.UserName;
                _username[1] = _userTable.Rows[0]["RealName"].ToString();
                _username[2] = _weekId;
                DataTable _iSEvaluatePeople = dllWeekPlanofManager.get(WeekPlanofManager.field.EvaluatePeople.ToString(), WeekPlanofManager.field.WeekPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count == 0 && objUserInfo.UserName != "admin")
                {
                    Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                }
                else
                {
                    string _url = "WeekPlanModify.aspx?Id=" + _weekId + "&WeekDate=" + this.drpWeekDate.SelectedValue + "&depart=" + department + "&Year=" + this.drpYear.SelectedValue + "&Quarter=" + this.drpQuarterDate.SelectedValue + "&Month=" + this.drpMonthDate.SelectedValue + "&Week=" + this.drpWeekDate.SelectedValue;
                    Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
                    return;
                }
            }

        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能查看一个周计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个周计划", Page);
            return;
        }
    }


    /// <summary>
    /// 周计划添加
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string _url = "WeekPlanAddAdmin.aspx?Year=" + this.drpYear.SelectedValue + "&Quarter=" + this.drpQuarterDate.SelectedValue + "&Month=" + this.drpMonthDate.SelectedValue + "&Week=" + this.drpWeekDate.SelectedValue;
        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=400,width=920,top=200,left=80,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
    }

    /// <summary>
    /// 删除本周
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelWeekPlan_Click(object sender, EventArgs e)
    {
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (this.gdvWeekPlan.DataKeys[i]["WeekPlanId"] != null && this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {
                    _count++;
                    object[] _value = new object[1];
                    _value[0] = Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                    _valueList.Add(_value);
                }
            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择要删除的周计划", Page);
        }
        if (_count >= 1)
        {
            int result = dllWeekPlanofManager.delWithTransaction(WeekPlanofManager.field.WeekPlanId.ToString(), _valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("删除周计划未成功，请重试");
            }
            else
            {
                //绑定

                bindGridView(this.gdvWeekPlan);
                bindGridView(this.gdvPreWeekPlan);
                bindGridView(this.gdvPreWeekPlanNoCompelete);
                bindGridView(this.gdvWeekPlanContinue);
                bindWeekRemind();
            }
        }
    }

    /// <summary>
    /// 删除上周未完成
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelPreWeekNoCompelete_Click(object sender, EventArgs e)
    {
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvPreWeekPlanNoCompelete.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreWeekPlanNoCompelete.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"] != null && this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {
                    _count++;
                    object[] _value = new object[1];
                    _value[0] = Convert.ToInt32(this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"].ToString());
                    _valueList.Add(_value);
                }
            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择要删除的周计划", Page);
        }
        if (_count >= 1)
        {
            int result = dllWeekPlanofManager.delWithTransaction(WeekPlanofManager.field.WeekPlanId.ToString(), _valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("删除周计划未成功，请重试");
            }
            else
            {
                //绑定

                bindGridView(this.gdvWeekPlan);
                bindGridView(this.gdvPreWeekPlan);
                bindGridView(this.gdvPreWeekPlanNoCompelete);
                bindGridView(this.gdvWeekPlanContinue);
                bindWeekRemind();
            }
        }
    }

    /// <summary>
    /// 删除持续进行
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelWeekContinue_Click(object sender, EventArgs e)
    {
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvWeekPlanContinue.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlanContinue.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"] != null && this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {
                    _count++;
                    object[] _value = new object[1];
                    _value[0] = Convert.ToInt32(this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString());
                    _valueList.Add(_value);
                }
            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择要删除的周计划", Page);
        }
        if (_count >= 1)
        {
            int result = dllWeekPlanofManager.delWithTransaction(WeekPlanofManager.field.WeekPlanId.ToString(), _valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("删除周计划未成功，请重试");
            }
            else
            {
                //绑定

                bindGridView(this.gdvWeekPlan);
                bindGridView(this.gdvPreWeekPlan);
                bindGridView(this.gdvPreWeekPlanNoCompelete);
                bindGridView(this.gdvWeekPlanContinue);
                bindWeekRemind();
            }
        }
    }


    /// <summary>
    /// 显示流程
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnflow_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int _weekId = 0;
        //上周
        for (int i = 0; i < this.gdvPreWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvPreWeekPlan.DataKeys[i]["WeekPlanId"] != null && this.gdvPreWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {

                    _weekId = Convert.ToInt32(this.gdvPreWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        //本周
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvWeekPlan.DataKeys[i]["WeekPlanId"] != null && this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {

                    _weekId = Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        //上周未完成
        for (int i = 0; i < this.gdvPreWeekPlanNoCompelete.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreWeekPlanNoCompelete.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"] != null && this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {

                    _weekId = Convert.ToInt32(this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        //持续计划
        for (int i = 0; i < this.gdvWeekPlanContinue.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlanContinue.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"] != null && this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {

                    _weekId = Convert.ToInt32(this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        if (_count == 1)
        {
            string _url = "../WebCommon/VerifyCircruitDisplay.aspx?PlanId=" + _weekId + "&PlanType=3";
            Page.RegisterStartupScript("windowOpen",
               "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=150,width=550,top=250,left=300,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");


        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能查看一个周计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个周计划", Page);
            return;
        }
    }



    /// <summary>
    /// 年份改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpQuarterDate);
        bindDropDownList(this.drpMonthDate);
        bindDropDownList(this.drpWeekDate);
        IsManager();
    }



    /// <summary>
    /// 年周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpQuarterDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpMonthDate);
        bindDropDownList(this.drpWeekDate);
        IsManager();
    }


    /// <summary>
    /// 月周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpMonthDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpWeekDate);
        IsManager();
    }

    /// <summary>
    /// 周周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpWeekDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindGridView(this.gdvWeekPlan);
        bindGridView(this.gdvPreWeekPlan);
        bindGridView(this.gdvPreWeekPlanNoCompelete);
        bindGridView(this.gdvWeekPlanContinue);
        bindWeekRemind();
        this.btnAddWeekSummary.Visible = true;
        this.btnAddPreWeekSummary.Visible = true;
        this.btnSaveWeekSummary.Visible = false;
        this.btnSavePreWeekSummary.Visible = false;
        IsManager();
    }


    /// <summary>
    /// 修改本周工作提醒
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifyWeekRemind_Click(object sender, EventArgs e)
    {
        if (this.lblWeekRemind.Text.Length != 0)
        {
            string _department = Server.UrlEncode(this.drpDepartment.SelectedItem.Text);
            string _url = "ModifyWeekRemind.aspx?Department=" + _department + "&WeekDate=" + this.drpWeekDate.SelectedValue + "&Date=" + this.drpWeekDate.SelectedValue;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','monthRemind','height=250,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
        else
        {
            Utility.HttpHelp.alert("无本周工作提醒", Page);
        }
        bindWeekRemind();
    }

    /// <summary>
    /// 修改上周工作提醒
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifyPreWeelRemin_Click(object sender, EventArgs e)
    {
        if (this.lblPreWeekRemind.Text.Length != 0)
        {
            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            int _preWeekDate = dllWeekDateManager.getPreWeekDate(_value);

            string _department = Server.UrlEncode(this.drpDepartment.SelectedItem.Text);
            string _url = "ModifyWeekRemind.aspx?Department=" + _department + "&WeekDate=" + _preWeekDate + "&Date=" + this.drpWeekDate.SelectedValue;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','monthRemind','height=250,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");

        }
        else
        {
            Utility.HttpHelp.alert("无上周工作提醒", Page);
        }
        bindWeekRemind();
    }


    /// <summary>
    /// 修改评估事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPreWeekEvalute_Click(object sender, EventArgs e)
    {
        int _count = 0;
        string _weekPlanId = "";
        int _noComplete = 0;
        for (int i = 0; i < this.gdvPreWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                _count++;
                _weekPlanId = this.gdvPreWeekPlan.DataKeys[i]["WeekPlanId"].ToString();
                _noComplete = int.Parse(this.gdvPreWeekPlan.DataKeys[i]["NoCompleteCount"].ToString());
            }
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能选择一个计划", Page);
        }
        if (_count == 1)
        {
            //if (objUserInfo.UserName == "admin" && _noComplete > 2)
            //{
            //    Utility.HttpHelp.alert("不可以修改多次未完成的计划评估意见", Page);
            //}
            //else
            //{
            string _department = Server.UrlEncode(this.drpDepartment.SelectedItem.Text);
            string _url = "ModifyEvaluate.aspx?WeekPlanId=" + _weekPlanId + "&department=" + _department + "&Date=" + this.drpWeekDate.SelectedValue;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','monthPlan','height=250,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
            //}
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
        }
    }


    /// <summary>
    /// 下载Excel文件方法(弹出对话框)
    /// </summary>
    /// <param name="filename">路径</param>
    /// <param name="strname">文件名</param>
    protected void DownloadFile(string filename, string strname)
    {
        string saveFileName = "";
        int intStart = filename.LastIndexOf('\\') + 1;
        saveFileName = filename.Substring(intStart, filename.Length - intStart);
        FileStream MyFileStream;
        long FileSize;

        String path = Request.PhysicalApplicationPath;
        path = path.Substring(0, path.LastIndexOf("\\"));
        path += "\\Excel\\Week\\";
        path += strname;
        MyFileStream = new FileStream(path, FileMode.Open);
        FileSize = MyFileStream.Length;

        byte[] Buffer = new byte[(int)FileSize];
        MyFileStream.Read(Buffer, 0, (int)FileSize);
        MyFileStream.Close();

        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(saveFileName));
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.ContentType = "application/vnd.ms-excel";

        Response.BinaryWrite(Buffer);
        Response.Flush();
        Response.Close();
        Response.End();
    }

    /// <summary>
    /// 写入excel
    /// </summary>
    /// <param name="strFilePathName"></param>
    /// <param name="objDataGrid"></param>
    /// <param name="strHeader"></param>
    /// <param name="strFooter"></param>
    /// <returns></returns>
    public static bool ExportToExcel(string strFilePathName, GridView objDataGrid, string strHeader, string strFooter)
    {
        //返回值
        bool bReturn = false;

        //判断datagrid是否为空
        if (null == objDataGrid)
        {
            return bReturn;
        }
        //表格的样式
        COM.Excel.cExcelFile objExcel = new COM.Excel.cExcelFile();
        int a = objExcel.CreateFile(strFilePathName);

        objExcel.PrintGridLines = false;
        COM.Excel.cExcelFile.MarginTypes mt1 = COM.Excel.cExcelFile.MarginTypes.xlsTopMargin;
        COM.Excel.cExcelFile.MarginTypes mt2 = COM.Excel.cExcelFile.MarginTypes.xlsLeftMargin;
        COM.Excel.cExcelFile.MarginTypes mt3 = COM.Excel.cExcelFile.MarginTypes.xlsRightMargin;
        COM.Excel.cExcelFile.MarginTypes mt4 = COM.Excel.cExcelFile.MarginTypes.xlsBottomMargin;
        double height = 1.5;
        objExcel.SetMargin(ref mt1, ref height);
        objExcel.SetMargin(ref mt2, ref height);
        objExcel.SetMargin(ref mt3, ref height);
        objExcel.SetMargin(ref mt4, ref height);
        COM.Excel.cExcelFile.FontFormatting ff = COM.Excel.cExcelFile.FontFormatting.xlsNoFormat;
        string font = "Arial";
        short fontsize = 12;
        objExcel.SetFont(ref font, ref fontsize, ref ff);



        byte b1 = 1, b2 = 12;
        short s3 = 18;
        objExcel.SetColumnWidth(ref b1, ref b2, ref s3);

        string header = strHeader;
        string footer = strFooter;
        objExcel.SetHeader(ref header);
        objExcel.SetFooter(ref footer);

        COM.Excel.cExcelFile.ValueTypes vt = COM.Excel.cExcelFile.ValueTypes.xlsText;
        COM.Excel.cExcelFile.CellFont cf = COM.Excel.cExcelFile.CellFont.xlsFont0;
        COM.Excel.cExcelFile.CellAlignment ca = COM.Excel.cExcelFile.CellAlignment.xlsLeftAlign;
        COM.Excel.cExcelFile.CellHiddenLocked chl = COM.Excel.cExcelFile.CellHiddenLocked.xlsNormal;
        //定义表格的起始点 

        int iFormat = 0;
        int iOutRow = 0;
        int iOutCol = 0;
        int iRowCount = 0;
        //获得该datagrid的列的数量
        int iColCount = objDataGrid.Columns.Count;


        iRowCount = objDataGrid.Rows.Count;


        //表头

        for (int j = 1; j < iColCount; j++)
        {
            if (objDataGrid.Columns[j].Visible == false)
            {
                continue;
            }
            //显示的信息
            object objValue = objDataGrid.Columns[j].HeaderText;
            iOutRow = 1;
            iOutCol = j + 1;
            objExcel.WriteValue(ref vt, ref cf, ref ca, ref chl, ref iOutRow,
                ref iOutCol, ref objValue, ref iFormat);
        }
        //内容
        for (int i = 1; i <= iRowCount; i++)
        {
            for (int j = 0; j < iColCount; j++)
            {
                if (objDataGrid.Columns[j].Visible == false)
                {
                    continue;
                }
                //显示的信息
                object objValue = objDataGrid.Rows[i - 1].Cells[j].Text;
                iOutRow = i + 1;
                iOutCol = j + 1;
                objExcel.WriteValue(ref vt, ref cf, ref ca, ref chl, ref iOutRow,
                    ref iOutCol, ref objValue, ref iFormat);
            }
        }
        bReturn = true;
        objExcel.CloseFile();
        return bReturn;
    }


    /// <summary>
    /// 导出上周计划excel
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcelPreWeek_Click(object sender, EventArgs e)
    {
        if (this.gdvPreWeekPlan.Rows.Count > 1)
        {
            string str = this.drpWeekDate.SelectedItem.Text + "-上周计划";
            string strname = str + ".xls";

            String path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            //删除过期
            string[] filename = Directory.GetFiles(path);
            for (int i = 0; i < filename.Length; i++)
            {
                path = filename[i];
                FileInfo fi = new FileInfo(path);
                if (DateTime.Now.ToShortDateString() == fi.CreationTime.ToShortDateString())
                {
                    System.IO.File.Delete(path);
                }
            }
            path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            path += strname;
            ExportToExcel(path, this.gdvPreWeekPlan, "aa", "bb");
            DownloadFile(path, strname);
        }
        else
        {
            Utility.HttpHelp.alert("上周计划没有数据", Page);
        }
    }


    /// <summary>
    /// 导出本周
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcelWeek_Click(object sender, EventArgs e)
    {
        if (this.gdvWeekPlan.Rows.Count > 1)
        {
            string str = this.drpWeekDate.SelectedItem.Text + "-本周计划";
            string strname = str + ".xls";

            String path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            //删除过期
            string[] filename = Directory.GetFiles(path);
            for (int i = 0; i < filename.Length; i++)
            {
                path = filename[i];
                FileInfo fi = new FileInfo(path);
                if (DateTime.Now.ToShortDateString() == fi.CreationTime.ToShortDateString())
                {
                    System.IO.File.Delete(path);
                }
            }
            path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            path += strname;
            ExportToExcel(path, this.gdvWeekPlan, "aa", "bb");
            DownloadFile(path, strname);
        }
        else
        {
            Utility.HttpHelp.alert("本周计划没有数据", Page);
        }
    }


    /// <summary>
    /// 导出上周未完成
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcelPreWeekNoCom_Click(object sender, EventArgs e)
    {
        if (this.gdvPreWeekPlanNoCompelete.Rows.Count > 1)
        {
            string str = this.drpWeekDate.SelectedItem.Text + "-上周未完成";
            string strname = str + ".xls";

            String path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            //删除过期
            string[] filename = Directory.GetFiles(path);
            for (int i = 0; i < filename.Length; i++)
            {
                path = filename[i];
                FileInfo fi = new FileInfo(path);
                if (DateTime.Now.ToShortDateString() == fi.CreationTime.ToShortDateString())
                {
                    System.IO.File.Delete(path);
                }
            }
            path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            path += strname;
            ExportToExcel(path, this.gdvPreWeekPlanNoCompelete, "aa", "bb");
            DownloadFile(path, strname);
        }
        else
        {
            Utility.HttpHelp.alert("上周未完成计划没有数据", Page);
        }
    }


    /// <summary>
    /// 导出持续周
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcelWeekContinue_Click(object sender, EventArgs e)
    {
        if (this.gdvWeekPlanContinue.Rows.Count > 1)
        {
            string str = this.drpWeekDate.SelectedItem.Text + "-上周未完成";
            string strname = str + ".xls";

            String path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            //删除过期
            string[] filename = Directory.GetFiles(path);
            for (int i = 0; i < filename.Length; i++)
            {
                path = filename[i];
                FileInfo fi = new FileInfo(path);
                if (DateTime.Now.ToShortDateString() == fi.CreationTime.ToShortDateString())
                {
                    System.IO.File.Delete(path);
                }
            }
            path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            path += strname;
            ExportToExcel(path, this.gdvWeekPlanContinue, "aa", "bb");
            DownloadFile(path, strname);
        }
        else
        {
            Utility.HttpHelp.alert("持续计划没有数据", Page);
        }
    }


    /// <summary>
    /// 到处Excel
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnToExcel_Click(object sender, EventArgs e)
    {
        GridView[] _gridView = new GridView[4];
        _gridView[0] = this.gdvPreWeekPlan;
        _gridView[1] = this.gdvWeekPlan;
        _gridView[2] = this.gdvPreWeekPlanNoCompelete;
        _gridView[3] = this.gdvWeekPlanContinue;
        Utility.Comm.WeekToExcel(GridViewToDataTable(_gridView), this.drpDepartment.SelectedItem.Text, this.drpQuarterDate.SelectedItem.Text + this.drpMonthDate.SelectedItem.Text + this.drpWeekDate.SelectedItem.Text, this.lblPreWeekRemind.Text, this.lblWeekRemind.Text);
    }

    /// <summary>
    /// GridView转DataTable
    /// </summary>
    DataTable[] GridViewToDataTable(GridView[] _sourceGridView)
    {
        DataTable[] _targetDataTable = new DataTable[_sourceGridView.Length];
        for (int i = 0; i < _targetDataTable.Length; i++)
        {
            _targetDataTable[i] = new DataTable();
            DataColumn dc = new DataColumn();
            //根据源GridView循环创建目标DataTable列
            for (int j = 0; j < _sourceGridView[i].Columns.Count; j++)
            {
                if (_sourceGridView[i].Columns[j].Visible == true)
                {
                    dc = new DataColumn(_sourceGridView[i].Columns[j].HeaderText);
                    _targetDataTable[i].Columns.Add(dc);
                }
            }
            //根据源GridView循环创建目标DataTable行
            for (int j = 0; j < _sourceGridView[i].Rows.Count; j++)
            {
                DataRow dr = _targetDataTable[i].NewRow();
                for (int k = 0; k < _sourceGridView[i].Columns.Count; k++)
                {

                    if (_sourceGridView[i].Columns[k].Visible == true && k < _targetDataTable[i].Columns.Count)
                    {

                        dr[k] = _sourceGridView[i].Rows[j].Cells[k].Text;


                    }

                }
                _targetDataTable[i].Rows.Add(dr);
            }

        }
        return _targetDataTable;
    }


    /// <summary>
    /// 上周取消评估
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPreWeekCancelEvalation_Click(object sender, EventArgs e)
    {
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvPreWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (this.gdvPreWeekPlan.DataKeys[i]["WeekPlanId"] != null && this.gdvPreWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {
                    _count++;
                    object[] _value = new object[1];
                    _value[0] = Convert.ToInt32(this.gdvPreWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                    _valueList.Add(_value);
                }
            }
        }

        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择要取消评估的周计划", Page);
        }
        if (_count > 0)
        {
            int result = this.dllWeekPlanofManager.editWithTransaction(WeekPlanofManager.field.WeekPlanId.ToString(), _valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("取消评估周计划未成功，请重试！");
            }
            else
            {
                bindGridView(this.gdvPreWeekPlan);
            }
        }
    }

    /// <summary>
    /// 本周取消评估
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnWeekCancelEvalation_Click(object sender, EventArgs e)
    {
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (this.gdvWeekPlan.DataKeys[i]["WeekPlanId"] != null && this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {
                    _count++;
                    object[] _value = new object[1];
                    _value[0] = Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                    _valueList.Add(_value);
                }
            }
        }

        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择要取消评估的周计划", Page);
        }
        if (_count > 0)
        {
            int result = this.dllWeekPlanofManager.editWithTransaction(WeekPlanofManager.field.WeekPlanId.ToString(), _valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("取消评估周计划未成功，请重试！");
            }
            else
            {
                bindGridView(this.gdvWeekPlan);
            }
        }
    }

    /// <summary>
    /// 上周未完成取消评估
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPreWeekNoCompCancelEvalation_Click(object sender, EventArgs e)
    {
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvPreWeekPlanNoCompelete.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreWeekPlanNoCompelete.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"] != null && this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {
                    _count++;
                    object[] _value = new object[1];
                    _value[0] = Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                    _valueList.Add(_value);
                }
            }
        }

        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择要取消评估的周计划", Page);
        }
        if (_count > 0)
        {
            int result = this.dllWeekPlanofManager.editWithTransaction(WeekPlanofManager.field.WeekPlanId.ToString(), _valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("取消评估周计划未成功，请重试！");
            }
            else
            {
                bindGridView(this.gdvPreWeekPlanNoCompelete);
            }
        }
    }

    /// <summary>
    /// 持续取消评估
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnContinueCancelEvalation_Click(object sender, EventArgs e)
    {
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvWeekPlanContinue.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlanContinue.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"] != null && this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {
                    _count++;
                    object[] _value = new object[1];
                    _value[0] = Convert.ToInt32(this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString());
                    _valueList.Add(_value);
                }
            }
        }

        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择要取消评估的周计划", Page);
        }
        if (_count > 0)
        {
            int result = this.dllWeekPlanofManager.editWithTransaction(WeekPlanofManager.field.WeekPlanId.ToString(), _valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("取消评估周计划未成功，请重试！");
            }
            else
            {
                bindGridView(this.gdvWeekPlanContinue);
            }
        }
    }





    protected void btnAddPreWeekSummary_Click(object sender, EventArgs e)
    {
        this.btnSavePreWeekSummary.Visible = true;
        this.btnAddPreWeekSummary.Visible = false;
        this.txtPreWeekSummary.ReadOnly = false;
        if (this.txtPreWeekSummary.Text == "注：工作总结不少于3条，总字数不少于60个字。")
        {
            this.txtPreWeekSummary.Text = "";
        }
        //this.lblPreWeekSummary.Visible = false;
    }
    protected void btnAddWeekSummary_Click(object sender, EventArgs e)
    {
        this.btnSaveWeekSummary.Visible = true;
        this.btnAddWeekSummary.Visible = false;
        this.txtWeekSummary.ReadOnly = false;
        if (this.txtWeekSummary.Text == "注：工作部署不少于3条，总字数不少于60个字。")
        {
            this.txtWeekSummary.Text = "";
        }
        //this.lblWeekSummary.Visible = false;
    }



    protected void btnSavePreWeekSummary_Click(object sender, EventArgs e)
    {
        if (this.drpDepartment.SelectedItem.Text != "请选择部门")
        {
            if (sender.Equals(this.btnSavePreWeekSummary))
            {
                if (this.txtPreWeekSummary.Text.Length < 60)
                {
                    Utility.HttpHelp.alert("字数不得少于60字！", this.Page);
                    return;
                }
            }
            else
            {
                if (this.txtWeekSummary.Text.Length < 60)
                {
                    Utility.HttpHelp.alert("字数不得少于60字！", this.Page);
                    return;
                }
            }
            if (this.HWeekSummaryId.Value.Length > 0)
            {
               
                //修改
                object[] _value = new object[7];
                _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
                _value[1] = this.txtPreWeekSummary.Text;
                _value[2] = this.txtWeekSummary.Text;
                _value[3] = objUserInfo.UserName;
                BLL.UserInfoManager dllUserInfo = new BLL.UserInfoManager();
                DataTable dt = dllUserInfo.get(BLL.UserInfoManager.field.UserName.ToString(), new object[] { objUserInfo.UserName });
                _value[4] = Convert.ToInt32(dt.Rows[0]["UserId"]);
                _value[5] = this.drpDepartment.SelectedItem.Text;
                _value[6] = Convert.ToInt32(this.HWeekSummaryId.Value);
                int val = new BLL.WeekSummary().editWeekSummary(_value);
                if (val > 0)
                {
                    bindGridView(this.gdvPreWeekPlan);
                }
                else
                {
                    Utility.HttpHelp.alert("修改失败", this.Page);
                }
            }
            else
            {
                //添加
                object[] _value = new object[5];
                _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
                _value[1] = this.txtPreWeekSummary.Text;
                _value[2] = this.txtWeekSummary.Text;
                _value[3] = objUserInfo.UserName;
                _value[4] = this.drpDepartment.SelectedItem.Text;
                int val = new BLL.WeekSummary().add(_value);
                if (val > 0)
                {
                    bindGridView(this.gdvPreWeekPlan);
                }
                else
                {
                    Utility.HttpHelp.alert("添加失败", this.Page);
                }
            }
            if (sender.Equals(this.btnSaveWeekSummary))
            {
                this.btnAddWeekSummary.Visible = true;
                this.btnSaveWeekSummary.Visible = false;
                this.txtWeekSummary.ReadOnly = false;
                //this.lblWeekSummary.Visible = true;
            }
            if (sender.Equals(this.btnSavePreWeekSummary))
            {
                this.btnAddPreWeekSummary.Visible = true;
                this.btnSavePreWeekSummary.Visible = false;
                this.txtPreWeekSummary.ReadOnly = false;
                //this.lblPreWeekSummary.Visible = true;
            }
        }
        else
        {
            Utility.HttpHelp.alert("请选择部门", this.Page);
        }
    }



    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (this.HWeekSummaryId.Value.Length > 0)
        {
            if (sender.Equals(this.btnUploadWeekSummary))
            {
                //定向到添加本月附件路径页面
                string _url = "../WebCommon/AttachmentPath.aspx?PlanId=" + this.HWeekSummaryId.Value + "&PlanType=17&Url=WeekPlanList.aspx";
                Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=40,width=400,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
            }
            else
            {
                //定向到添加上月附件路径页面
                string _url = "../WebCommon/AttachmentPath.aspx?PlanId=" + this.HWeekSummaryId.Value + "&PlanType=14&Url=WeekPlanList.aspx";
                Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=40,width=400,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
            }
        }
        else
        {
            if (sender.Equals(this.btnUploadWeekSummary))
            {
                Utility.HttpHelp.alert("请先添加本周总结", this.Page);
            }
            else
            {
                Utility.HttpHelp.alert("请先添加上周总结", this.Page);
            }

        }
    }
    protected void btnDownWeekSummary_Click(object sender, EventArgs e)
    {
        if (sender.Equals(this.btnDownWeekSummary))
        {
            string path = this.HAttachmentPath.Value;
            FileDownload(path);
        }
        else
        {
            string path = this.HPreAttachmentPath.Value;
            FileDownload(path);
        }
    }


    ///   <summary>   
    ///   文件下载   
    ///   </summary>   
    ///   <param   name="FullFileName"></param>   
    private void FileDownload(string strFileName)
    {

        FileInfo DownloadFile = new FileInfo(strFileName);
        if (!DownloadFile.Exists)
        {
            Utility.HttpHelp.alert("无附件,请与管理员联系", Page);
            return;
        }
        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName.Substring(strFileName.LastIndexOf('\\') + 1), System.Text.Encoding.UTF8));
        // Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());

        Response.WriteFile(DownloadFile.FullName);
        Response.Flush();
        Response.End();

    }
}
